//
//  CoverView.m
//  overFlow
//
//  Created by 于 百和 on 13-4-17.
//  Copyright (c) 2013年 于 百和. All rights reserved.
//

#import "CoverView.h"

@implementation CoverView

@synthesize delegate,nFingerDistance;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        
        UIImageView * lineView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 2, 128)];
        [self addSubview:lineView];
        [lineView release];
        [lineView setImage:[UIImage imageNamed:@"AllAuto_Image_split"]];
        lineView.center = CGPointMake(self.center.x+25, 600);
        
        btnEnterCar = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 115, 25)];
        [self addSubview:btnEnterCar];
        [btnEnterCar release];
        [btnEnterCar setImage:[UIImage imageNamed:@"AllAuto_Image_EnterCar"] forState:UIControlStateNormal];
        [btnEnterCar addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
        btnEnterCar.center = CGPointMake(lineView.center.x+57, lineView.center.y+7);
        
        logoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 173, 40)];
        [self addSubview:logoImageView];
        [logoImageView release];
        logoImageView.center = CGPointMake(lineView.center.x-87, lineView.center.y+40);
    }
    return self;
}

-(void)onClick:(UIButton *)sender
{
    [delegate EnterDetail];
}

-(void)SetLogoImage:(NSString *)imagepath
{
   
    UIImage * image = [UIImage imageWithContentsOfFile:imagepath];
    logoImageView.image = image;

}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    ptTouchBegin = [[touches anyObject] locationInView:self];
    orTouchBegin = [[touches anyObject] locationInView:self];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesMoved:touches withEvent:event];
    //@hanhaidi@0815
//    CGPoint ptCur = [[touches anyObject] locationInView:self];
//    
//    if ( ptCur.x > ptLast.x && (ptCur.x - ptTouchBegin.x) > nFingerDistance )
//    {
//        [delegate toPreviousPage];
//        ptTouchBegin = ptCur;
//    }
//    else if ( ptCur.x < ptLast.x && (ptTouchBegin.x - ptCur.x) > nFingerDistance )
//    {
//        [delegate toNextPage];
//        
//        ptTouchBegin = ptCur;
//    }
//    
//    ptLast = ptCur;
    
    
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesCancelled:touches withEvent:event];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    [super touchesEnded:touches withEvent:event];
    CGPoint ptCur = [[touches anyObject] locationInView:self];
    if ( ABS(orTouchBegin.x - ptCur.x) < 20 ){
        [delegate click];
    }
    
    //@hanhaidi@0815 实现无论滑动多远，一次滑动触发一次换页
    if ( ptCur.x > ptTouchBegin.x && (ptCur.x - ptTouchBegin.x) > nFingerDistance )
    {
        [delegate toPreviousPage];
    }
    else if ( ptCur.x < ptTouchBegin.x && (ptTouchBegin.x - ptCur.x) > nFingerDistance )
    {
        [delegate toNextPage];
    }

}



@end
